﻿using FluentValidation;
using Microsoft.AspNetCore.Components.Routing;

namespace FlumentValidation
{
    public class AddNewsUserRequestValidator:AbstractValidator<AddNewsUserRequest>
    {
        public AddNewsUserRequestValidator() {
            RuleFor(x => x.email).NotNull().EmailAddress()
                .Must(x => x.EndsWith("@163.com") || x.EndsWith("@qq.com"))
                .WithMessage("邮箱必须不能空，符合邮箱格式，必须已@163.com，@qq.com结尾");

            RuleFor(x => x.username).NotNull().Length(3, 10);
            RuleFor(x => x.password1).Equal(x => x.password2)
                .WithMessage(x => $"密码{x.password1}和{x.password2}密码不一致");

        }
    }
}
